package cfdt.ldl.web.service.bus;

import cfdt.common.vo.PageBaseResponse;
import cfdt.common.vo.PageData;
import cfdt.ldl.business.api.feign.BusinessFeign;
import cfdt.ldl.business.api.request.GetLawyerInfoListBusinessRequest;
import cfdt.common.exception.CodeException;
import cfdt.ldl.core.entity.LawyerInfo;
import cfdt.ldl.web.api.request.GetLawyerInfoListWebRequest;
import cfdt.ldl.web.api.vo.LawyerInfoLessVO;
import cn.hutool.core.bean.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Service
public class LawyerInfoWebService {

    @Autowired
    private BusinessFeign businessFeign;

    /**
     * 根据ID获取律师信息
     *
     * @param request
     * @return
     */
    @PostMapping("/getList")
    @ResponseBody
    public PageBaseResponse<LawyerInfoLessVO> getList(@RequestBody GetLawyerInfoListWebRequest request) throws CodeException {
        GetLawyerInfoListBusinessRequest getLawyerInfoListRequest = new GetLawyerInfoListBusinessRequest();
        // 属性拷贝
        BeanUtil.copyProperties(request, getLawyerInfoListRequest);
        // 获取数据
        PageBaseResponse<LawyerInfo> busPage = businessFeign.getLawyerInfoList(getLawyerInfoListRequest);
        PageData<LawyerInfo> busPageData = busPage.getData();
        // 数据集合转换
        List<LawyerInfoLessVO> list = BeanUtil.copyToList(busPageData.getList(), LawyerInfoLessVO.class);
        // 响应
        return PageBaseResponse.success(PageData.data(busPageData, list));
    }
}
